package com.dhcc.his.blh.student;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.dhcc.framework.app.blh.BaseAbstractBlh;
import com.dhcc.framework.common.BaseConstants;
import com.dhcc.framework.common.PageModel;
import com.dhcc.framework.exception.DataBaseException;
import com.dhcc.framework.transmission.dto.BaseAbstractDto;
import com.dhcc.his.dto.student.StudentDto;
import com.dhcc.his.entity.student.Student;
import com.dhcc.his.service.student.StudentService;

/**
 * 
 * 描述: TODO<br/>
 * 公司: 东华医为科技有限公司<br/>
 * 版权: dhcc 2019<br/>
 *
 * @author CodeGenUtils
 * @version V1.0
 */
@Component
public class StudentBlh extends BaseAbstractBlh<StudentDto> {

	private static Log logger = LogFactory.getLog(StudentBlh.class);

	@Resource
	private StudentService studentService;

	public StudentBlh() {
		logger.debug("StudentBlh Init");
	}
	
	/**
	 * 
	 * 进入某个列表的入口方法（分页查询方法）
	 * @param basedto
	 */
	public void page(BaseAbstractDto basedto) {
		StudentDto dto = super.getExactlyDto(basedto);
		
		try {
			//调用service查询方法
			PageModel pageModel=studentService.page(dto);
			//不要删除这行代码，调用set是为以后 service层要加缓存
			dto.setPageModel(pageModel);
		} catch (Exception e) {
			logger.error(e);
			throw new DataBaseException(e.getMessage(), e);
		}
	}
	
	/**
	 * 
	 * 保存对象，若无ID则新建对象，若有ID则更新对象
	 * @param basedto
	 */
	public void save(BaseAbstractDto basedto) {
		StudentDto dto = super.getExactlyDto(basedto);
		
		try {
			//调用对应的service保存方法
			studentService.save(dto.getStudent());
			dto.setOperateSuccess(BaseConstants.OPERATE_SUCCESS);
		} catch (Exception e) {
			logger.error(e);
			throw new DataBaseException(e.getMessage(), e);
		}
	}
	
	/**
	 * 
	 * 删除
	 * @param basedto
	 */
	public void deleteById(BaseAbstractDto basedto) {
		StudentDto dto = super.getExactlyDto(basedto);
		
		try {
			//调用对应的service删除方法
			studentService.deleteById(dto.getStudent().getId());
			dto.setOperateSuccess(BaseConstants.OPERATE_SUCCESS);
		} catch (Exception e) {
			logger.error(e);
			throw new DataBaseException(e.getMessage(), e);
		}
	}
	
	/**
	 * 
	 * 根据ID查询实体的方法
	 * @param: basedto
	 *  
	 */
	public void findById(BaseAbstractDto basedto) {
		StudentDto dto = super.getExactlyDto(basedto);
		
		try {
			//调用对应的service查询某个实体的方法
			Student entity = studentService.findById(dto.getStudent().getId());
			//不要删除这行代码，调用set是为以后 service层要加缓存 
			dto.setStudent(entity);
		} catch (Exception e) {
			logger.error(e);
			throw new DataBaseException(e.getMessage(), e);
		}
	}
}
